﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
''' <summary>
''' 背景浓度对象，用于保存某一关心点或网格点不同的污染物不同平均时间的浓度
''' </summary>
''' <remarks></remarks>
<Serializable()> Public Class BackCon
    Implements ICloneable

    ''' <summary>
    ''' 用于储存多个污染物的背景浓度
    ''' </summary>
    ''' <remarks></remarks>
    Private m_PollutBackCon As New List(Of PollutBackCon)
    Property PollutBackCon() As List(Of PollutBackCon)
        Get
            Return Me.m_PollutBackCon
        End Get
        Set(ByVal value As List(Of PollutBackCon))
            Me.m_PollutBackCon = value
        End Set
    End Property
    ''' <summary>
    ''' 根据污染物的变化设置所有的污染物对应的背景浓度
    ''' </summary>
    ''' <param name="AllPolluts"></param>
    ''' <remarks></remarks>
    Public Sub PolluteChaged(ByVal AllPolluts As AllPolluts, ByVal disCart() As DiscCart)
        If Me.m_PollutBackCon.Count = 0 Then '如果为空，则重新设置
            For i As Integer = 0 To AllPolluts.AllSelectPollut.Length - 1
                Dim P_BackCon As New PollutBackCon
                m_PollutBackCon.Add(P_BackCon)
            Next
        Else '如果不为空，则需要进行调整
            Dim A As New List(Of PollutBackCon)
            For i As Integer = 0 To AllPolluts.AllSelectPollut.Length - 1
                Dim P_BackCon As New PollutBackCon
                A.Add(P_BackCon)
            Next

            For i As Integer = 0 To AllPolluts.AllSelectPollut.Length - 1
                A.Item(i) = New PollutBackCon
                A.Item(i).Name = AllPolluts.AllSelectPollut(i).Name
                Dim j As Integer = -99
                For j = 0 To Me.m_PollutBackCon.Count - 1
                    If Me.m_PollutBackCon.Item(j) IsNot Nothing AndAlso AllPolluts.AllSelectPollut(i).Name = Me.m_PollutBackCon(j).Name Then
                        A.Item(i) = Me.m_PollutBackCon.Item(j).Clone  '设置污染物所有的参数
                    End If
                Next
            Next
            Me.m_PollutBackCon = A
        End If


        For i As Integer = 0 To Me.m_PollutBackCon.Count - 1
            For j As Integer = 0 To Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon.Length - 1
                If Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon.Count = 0 Then
                    For k As Integer = 0 To disCart.Length - 1
                        Dim disBack As New DisCareBackCon
                        disBack.Con = -99
                        disBack.ID = disCart(k).ID
                        disBack.Name = disCart(k).Name
                        Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon.Add(disBack)

                    Next
                Else
                    Dim A As New List(Of DisCareBackCon)
                    For k As Integer = 0 To disCart.Length - 1
                        Dim disBack As New DisCareBackCon
                        disBack.Con = -99
                        disBack.ID = disCart(k).ID
                        disBack.Name = disCart(k).Name
                        A.Add(disBack)
                    Next
                    For L As Integer = 0 To disCart.Length - 1
                        For k As Integer = 0 To Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon.Count - 1
                            If disCart(L).Name = Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon.Item(k).Name Then
                                A.Item(L) = Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon.Item(k) '设置污染物所有的参数
                            End If
                        Next
                    Next
                    Me.m_PollutBackCon.Item(i).ArrayAverageTimeBackCon(j).ListCareBackCon = A
                End If
            Next
        Next

    End Sub

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj As New BackCon
        For i As Integer = 0 To Me.m_PollutBackCon.Count - 1
            obj.m_PollutBackCon.Add(Me.m_PollutBackCon.Item(i).Clone)
        Next
        Return obj
    End Function
End Class
